{extend name="adminheader:header"/}
{block name="content"}
<script type="text/html" id="photos-item-tpl">
    <li id="saved-image{id}">
        <input id="photo-{id}" type="hidden" name="photo_urls[]" value="{filepath}">
        <input class="form-control" id="photo-{id}-name" type="text" name="photo_names[]" value="{name}"
               style="width: 200px;" title="图片名称">
        <img id="photo-{id}-preview" src="{imgs}" style="height:36px;width: 36px;cursor: pointer;"
             onclick="imagePreviewDialog(this.src);">
        <a href="javascript:uploadOneImage('图片上传','#photo-{id}');">替换</a>
        <a href="javascript:(function(){$('#saved-image{id}').remove();})();">移除</a>
    </li>
</script>
	<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                	<div class="ibox-title">
                        <h5>添加商品</h5>
                    </div>
                    <div class="ibox-content">
                        <form action="{:url('/admin/Goods/addPost')}" method="post" class="form-horizontal js-ajax-form m-t">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">商品分类<span class="form-required">*</span></label>
                                <div class="col-md-6 col-sm-10">
                                     <select class="form-control" name="cid">
                                        <option value="">- - - 请选择类型 - - -</option>
                                        {if condition="$category neq null"}
                                            {volist name="category" id="vo"}
                                                <option value="{$vo.id}" {$vo['pid']==0?'disabled':''}>{$vo.name}</option>
                                            {/volist}
                                        {else/}
                                            <option value="" disabled="disabled">暂时无商品分类</option>
                                        {/if}
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">商品名称<span class="form-required">*</span></label>
                                <div class="col-md-6 col-sm-10">
                                    <input name="g_name" type="text" class="form-control" value="" placeholder="请输入商品名称" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">商品图<span class="form-required">*</span></label>
                                <div class="col-md-6 col-sm-10">
                                    <input type="hidden" name="g_pic[thumbnail]" id="thumbnail" value="">
                                    <ul id="photos" class="pic-list list-unstyled form-inline"></ul>
                                    <a href="javascript:uploadMultiImage('图片上传','#photos','photos-item-tpl');"
                                       class="btn btn-default btn-sm">选择图片</a>
                                </div>
                            </div>
                            <div class="form-group" id="f1">
                                <label class="col-sm-3 control-label">商品规格<span class="form-required">*</span></label>
                                <div class="col-md-1 col-sm-10">
                                    <input name="i_name1" type="text" class="form-control inp_lis" value="" placeholder="规格" />
                                </div>
                                <img src="/admin/img/add.png" width="30" height="30" style="cursor: pointer;" id="addiname" />
                                <img src="/admin/img/timg.jpg" width="30" height="30" style="cursor: pointer;" id="removeiname" />
                            </div>
                            <div class="form-group" id="f2">
                                <label class="col-sm-3 control-label">商品规格单价<span class="form-required">*</span></label>
                                <div class="col-md-1 col-sm-10">
                                    <input name="i_price1" type="text" class="form-control" value="" placeholder="单价" />
                                </div>
                            </div>
                            <div class="form-group" id="f3">
                                <label class="col-sm-3 control-label">数量<span class="form-required">*</span></label>
                                <div class="col-md-1 col-sm-10">
                                    <input name="i_number1" type="text" class="form-control" value="" placeholder="数量" />
                                </div>
                            </div>
                            <div class="form-group" id="f4">
                                <label class="col-sm-3 control-label">商品佣金<span class="form-required">*</span></label>
                                <div class="col-md-1 col-sm-10">
                                    <input name="i_commission1" type="text" class="form-control" value="" placeholder="佣金" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">数量的单位<span class="form-required">*</span></label>
                                <div class="col-md-6 col-sm-10">
                                    <input name="g_unit" type="text" class="form-control" value="" placeholder="数量的单位" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">当前价<span class="form-required">*</span></label>
                                <div class="col-md-6 col-sm-10">
                                    <input name="g_cprice" type="text" class="form-control" value="" placeholder="请输入当前价" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">原价<span class="form-required">*</span></label>
                                <div class="col-md-6 col-sm-10">
                                    <input name="g_oprice" type="text" class="form-control" value="" placeholder="请输入原价" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">展示地方<span class="form-required">*</span></label>
                                <div class="col-md-6 col-sm-10">
                                   <input type="radio" name="g_show" id="inlineRadio2" value="1" checked="checked" style="cursor: pointer;margin-right:5px"/>普通商品&nbsp;&nbsp;&nbsp;&nbsp;
                                   <input type="radio" name="g_show" id="inlineRadio3" value="2" style="cursor: pointer;margin-right:5px"/>官方活动
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">商品描述<span class="form-required">*</span></label>
                                <div class="col-md-6 col-sm-10">
                                    <textarea class="form-control" name="g_description" placeholder="请填写商品描述"></textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">商品信息<span class="form-required">*</span></label>
                                <div class="col-md-6 col-sm-10">
                                    <script id="content" name="g_content" type="text/plain"></script>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">状态<span class="form-required">*</span></label>
                                <div class="col-md-6 col-sm-10">
                                   <input type="radio" name="g_status" id="inlineRadio1" value="1"  checked="checked" style="cursor: pointer;margin-right:5px"/>新添加&nbsp;&nbsp;&nbsp;&nbsp;
                                   <input type="radio" name="g_status" id="inlineRadio2" value="2" style="cursor: pointer;margin-right:5px"/>上架&nbsp;&nbsp;&nbsp;&nbsp;
                                   <input type="radio" name="g_status" id="inlineRadio3" value="3" style="cursor: pointer;margin-right:5px"/>下架
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">添加时间<span class="form-required">*</span></label>
                                <div class="col-md-6 col-sm-10">
                                    <input class="form-control js-bootstrap-datetime" type="text" name="addtime" value="{:date('Y-m-d H:i',time())}">
                                </div>
                            </div>
                            <input type="hidden" name="length" value="" id="length"/>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-3">
                                    <button class="btn btn-primary js-ajax-submit" type="submit" id="btn">添加</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
<script src="/admin/js/admin.js"></script>
 <!-- 配置文件 -->
<script type="text/javascript" src="/admin/js/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="/admin/js/ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('content');
</script>
<script type="text/javascript">
    
    /* 添加商品的所有规格数据 */
    $('#addiname').click(function(){
        var iname = $("#f1").children('div');
        var iprice = $("#f2").children('div');
        var inumber = $("#f3").children('div');
        var icommission = $("#f4").children('div');
        {
            var lis=$(".inp_lis");
            for (var i=0;i<lis.length;i++) {

                var k=$(this).index(i)
            }
        let s=k;
        
            if(iname.length<=10){
                $('#f1').children('div:last').after('<div class="col-md-1 col-sm-10"><input name="i_name'+s+'" type="text" class="form-control" value="" placeholder="规格" /></div>');
            }
            
            if(iprice.length<=10){
                $('#f2').children('div:last').after('<div class="col-md-1 col-sm-10"><input name="i_price'+s+'" type="text" class="form-control" value="" placeholder="单价" /></div>');
            }

            if(inumber.length<=10){
                $('#f3').children('div:last').after('<div class="col-md-1 col-sm-10"><input name="i_number'+s+'" type="text" class="form-control" value="" placeholder="数量" /></div>');
            }

            if(icommission.length<=10){
                $('#f4').children('div:last').after('<div class="col-md-1 col-sm-10"><input name="i_commission'+s+'" type="text" class="form-control" value="" placeholder="佣金" /></div>');
            }
        }

    });

    /*  移除商品规格 */
    $('#removeiname').click(function(){
        var iname = $("#f1").children('div');
        var iprice = $("#f2").children('div');
        var inumber = $("#f3").children('div');
        var icommission = $("#f4").children('div');

        if(iname.length>=2){
           $('#f1').children('div:last').remove(); 
        }

        if(iprice.length>=2){
           $('#f2').children('div:last').remove();
        }

        if(inumber.length>=2){
           $('#f3').children('div:last').remove();
        }

        if(icommission.length>=2){
           $('#f4').children('div:last').remove(); 
        }

    });

    /* 计算商品规格的长度 */
    $('#btn').click(function(){
        var iname = $("#f1").children('div');
        var len = iname.length;
        $('#length').val(len);
    });

</script>
{/block}